<?php
include "connect/connect_dsccmis.php";
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
//XML Header
header("content-type:text/xml");
//GET Variable
$chkuse_date = $_GET["chkuse_date"];
$date_start = $_GET["date_start"];
$date_end = $_GET["date_end"];
$chkuse_prov = $_GET["chkuse_prov"];
$chkbox90 = $_GET["chkbox90"];
$chkbox94 = $_GET["chkbox94"];
$chkbox95 = $_GET["chkbox95"];
$chkbox96 = $_GET["chkbox96"];
$chkbox00 = $_GET["chkbox00"];
$cond_cause = $_GET["cond_cause"];
$cond_evntyp = $_GET["cond_evntyp"];
$user_type = $_GET["user_type"];

// condition of event date
$cond_date_star = "";
$cond_date_end = "";
if($chkuse_date){
	$cond_date_star = " and evndte >='".$date_start."'";
	$cond_date_end = " and evndte <='".$date_end."'";
}

// condition of province
$cond_prov = "";
if($chkuse_prov){
  	$cond_prov=$chkbox90." ".$chkbox94." ".$chkbox95." ".$chkbox96;
	$cond_prov=trim($cond_prov);
	$cond_prov=preg_replace("/\s+/","','",$cond_prov);
	$cond_prov="('".$cond_prov."')";
	if($chkbox00=="00"){
		$cond_prov = " and (prov in ".$cond_prov." or prov not in ('90','94','95','96'))";
	}else{
		$cond_prov=" and prov in ".$cond_prov;
	}
}

// condition of cause
// event cause
//$cond_cause = $_GET["cond_cause"];
if($cond_cause!=""){
	$cond_cause = " and cdscc in ".$cond_cause;
}


// event type
//$cond_evntyp = $_GET["cond_evntyp"];
if($cond_evntyp!=""){
	$cond_evntyp = " and mis_evntypid in ".$cond_evntyp;
}

// เซ็ตเงื่อนไขสำหรับ การบาดเจ็บ
//$cond_inj = "";
//if($chkbox_inj1 <> $chkbox_inj2){
//	$cond_inj = " and mis_losbody ='".$chkbox_inj1.$chkbox_inj2."'";
//}
// เซ็ตเงื่อนไขสำหรับ เพศ
//$cond_sex = "";
//if($chkbox_sex1 <> $chkbox_sex2){
//	$cond_sex = " and sex ='".$chkbox_sex1.$chkbox_sex2."'";
//}
// เซ็ตเงื่อนไขสำหรับ ศาสนา
//$cond_reg=$chkbox_reg1." ".$chkbox_reg2." ".$chkbox_reg3." ".$chkbox_reg4;
//$cond_reg=trim($cond_reg);
//$cond_reg=preg_replace("/\s+/","','",$cond_reg);
//if($cond_reg<>""){
//	$cond_reg="('".$cond_reg."')";
//	$cond_reg=" and reg in ".$cond_reg;
//}
//$user_type = $_GET["user_type"];
//mysql_query("set names utf8");
$sql = "select rolplcidgen,vill_name,tam_name,amp_name,prov_name,lat,lng,count(*) as c from gis_victim where 1 ".$cond_date_star.$cond_date_end.$cond_prov.$cond_cause.$cond_evntyp." group by rolplcidgen,vill_name,tam_name,amp_name,prov_name,lat,lng;";
//echo $sql;
$query = mysql_query($sql);
echo "<locations>";
// case group is 2,3,4,5
if(($user_type=="2") || ($user_type=="3") || ($user_type=="4") || ($user_type=="5")){
	while ($row=mysql_fetch_assoc($query)){
	//get list of victim
		$list_victim = "";
    	$sql2 = "select perid,nme,surnme,losbodynme from gis_victim where rolplcidgen='".$row['rolplcidgen']."'".$cond_date_star.$cond_date_end.$cond_prov.$cond_cause.$cond_evntyp;
    	$query2 = mysql_query($sql2);
		$i = 1;
		while ($row2=mysql_fetch_assoc($query2)){
			$list_victim = $list_victim."&lt;br&gt;"."&lt;a href=&quot;# &quot; onclick=&quot;javascript:popUp('show_victim_des.php?perid=".$row2['perid']."','400','300');&quot;&gt;"."&lt;b&gt;".$i.".&lt;/b&gt;".$row2['nme']." ".$row2['surnme']." ".$row2['losbodynme']."&lt;/a&gt;";
			$i++;
		}
	//--------------------------------------------
		echo '<location id="'.$row['rolplcidgen'].'" tam_name="'.$row['tam_name'].'" amp_name="'.$row['amp_name'].'" prov_name="'.$row['prov_name'].'" numvic="'.$row['c'].'" lat="'.$row['lat'].'" lng="'.$row['lng'].'" vill_name="'.$row['vill_name'].'" list_victim="'.$list_victim.'"/>';
	}
}else{ //case group is 1
	while ($row=mysql_fetch_assoc($query)){
	//get list of victim
		$list_victim = "";
		echo '<location id="'.$row['rolplcidgen'].'" tam_name="'.$row['tam_name'].'" amp_name="'.$row['amp_name'].'" prov_name="'.$row['prov_name'].'" numvic="'.$row['c'].'" lat="'.$row['lat'].'" lng="'.$row['lng'].'" vill_name="'.$row['vill_name'].'" list_victim="'.$list_victim.'"/>';
	}
}
echo "</locations>";

?>
